package xue;

import org.junit.Test;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.nio.charset.StandardCharsets;

public class Client1 {
    public static void main(String[] args) throws IOException {
        Socket s=new Socket("127.0.0.1",888);
        System.out.println("2");
        BufferedOutputStream out=new BufferedOutputStream(s.getOutputStream());
        BufferedInputStream in=new BufferedInputStream(s.getInputStream());
        String str="adfadadk";
        byte[] b=str.getBytes("UTF-8");
        out.write(b);
        out.flush();
        out.write("ok".getBytes(StandardCharsets.UTF_8));
        out.flush();
        s.shutdownOutput();
        byte[] b2=new byte[10];
//        System.out.println("???");
        String l=null;
        String l2=null;

      while( in.read(b2)!=-1){

          l=new String(b2,"Utf-8");
          l2=l.substring(l.length()-2,l.length());
          System.out.println(l2);
            if (l2.equals("ok")){
                in.close();
                s.close();
                break;
            }
        }
    }

    @Test
    public void aaa(){
        System.out.println("aaaaa");
    }
}
